﻿#region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Csla;

    using MarketPulse.BusinessLogic.Core;

#endregion

namespace MarketPulse.BusinessLogic.Common
{
    /// <summary>
    /// Class used as a (guid based enumeration) list that holds the possible types for Country.
    /// </summary>
    [Serializable]
    [Csla.Server.ObjectFactory("MarketPulse.DataAccess.Factory.PaymentTypeFactory, MarketPulse.DataAccess.Factory", "FetchInfoList")]
    public class PaymentTypeInfoList : MarketPulseReadOnlyListBase<PaymentTypeInfoList, PaymentTypeInfo>
    {
        #region Member Variables

            /// <summary>List to hold all the possible PaymentType values</summary>
            private static PaymentTypeInfoList mPaymentTypes;

        #endregion

        #region Constructors

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// via only the static factory methods provided.
            /// </summary>
            private PaymentTypeInfoList()
            {
            }

        #endregion

        #region Methods

            #region Factory Methods

                /// <summary>
                /// Method used to retrieve a list of PaymentType objects. Internally this accesses a static field so this
                /// class is effectively a lazily instantiated singleton.
                /// </summary>
                /// <returns>A valid (populated) list of PaymentType objects</returns>
                public static PaymentTypeInfoList GetAll()
                {
                    // Load the list if it's null
                    if (mPaymentTypes == null)
                    {
                        mPaymentTypes = DataPortal.Fetch<PaymentTypeInfoList>();
                    }
                    return mPaymentTypes;
                }

            #endregion

            /// <summary>
            /// Method used to find a single PaymentTypeInfo object from the collection based on the unique identifier supplied
            /// </summary>
            /// <param name="paymentTypeGuid">The guid that uniquely identifies the PaymentTypeInfo object to find</param>
            /// <returns>A valid PaymentTypeInfo object (populated or empty)</returns>
            public PaymentTypeInfo FindByGuid(Guid paymentTypeGuid)
            {
                var result = (from paymentType in this.Items
                              where paymentType.GUID == paymentTypeGuid
                              select paymentType).Single();

                return (PaymentTypeInfo)result;
            }

        #endregion

    }
}
